import { ReactNode, Suspense } from 'react'
import { hasToken } from '@/utils/storage'
import { Navigate, useLocation } from 'react-router-dom'

//权限路由组件
function PrivateRoute({ children }: { children: ReactNode }) {
  const location = useLocation()
  return (
    <>
      <Suspense>
        {hasToken() ? (
          children
        ) : (
          <Navigate to={{ pathname: '/login' }} state={{ from: location.pathname }}></Navigate>
        )}
      </Suspense>
    </>
  )
}
export default PrivateRoute
